<template>
  <div class="page">
    <van-nav-bar title="添加门店" left-arrow @click-left="goBack"/>
    <van-form class="page-content" :disabled="btnLoading" @submit="submit">
      <van-field :rules="[ $check('', true) ]" required label="门店名称" v-model="info.shopName" placeholder="请输入"/>
     
      <form-image :rules="[ $check('', true) ]" required label="商家LOGO" v-model="info.shopPhotBase"></form-image>
      <form-image :rules="[ $check('', true) ]" required label="商家图片" v-model="info.shopPhotUrl"></form-image>

      <van-field :rules="[ $check('', true) ]" required label="经纬度" readonly clickable :value="info.longitude ? `${ info.longitude },${ info.latitude }` : ''" placeholder="请选择经纬度" @click="selePosi"/>
      <van-field :rules="[ $check('', true) ]" required label="所在区域" v-model="info.region" placeholder="请输入"/>
      <van-field :rules="[ $check('', true) ]" required label="详细地址" v-model="info.shopSite" placeholder="请输入"/>
      
      <form-picker :rules="[ $check('', true) ]" required label="计费时间/小时" v-model="info.chargeTime" :option="option.chargeTime"/>
      <van-field :rules="[ $check('', true), $check('请输入数字', 'number') ]" required label="计费金额/元" v-model.number="info.shopSite" placeholder="请输入"/>
      <van-field :rules="[ $check('', true), $check('请输入数字', 'number') ]" required label="免费时长/分钟" v-model.number="info.freeTime" placeholder="请输入"/>
      <form-picker :rules="[ $check('', true) ]" required label="每日最高消费" v-model="info.highest" :option="option.highest"/>
      <van-field :rules="[ $check('', true) ]" required label="门店电话" v-model.number="info.shopTele" placeholder="请输入"/>
      <van-field :rules="[ $check('', true) ]" required label="营业时间" v-model.number="info.shopHours" placeholder="请输入"/>
      <form-picker :rules="[ $check('', true) ]" required label="门店类型" v-model="info.shopSortId" :option="option.shopSortId"/>
      <van-field :rules="[ $check('', true) ]" readonly clickable required label="门店管理人" v-model.number="info.userName" placeholder="请输入" @click="person.showBlank('user', [ 3 ])"/>
      <van-field readonly clickable label="服务商" v-model.number="info.qdsName" placeholder="请输入" @click="person.showBlank('qds', [ 4 ])">
        <template #button>
          <van-button v-if="info.qdsName" size="small" type="primary" @click.stop="() => {
            info.qdsName = '';
            info.qdsId = '';
          }">清除</van-button>
        </template>
      </van-field>
      <van-field readonly clickable label="业务员" :value="info.salesmanName" placeholder="选择业务员" @click="person.showBlank('salesman', [ 2 ])" v-if="roleType < 2"/>
      <form-picker :rules="[ $check('', true) ]" required label="地图显示" v-model="info.ifUsable" :option="option.ifUsable"/>
      <form-picker :rules="[ $check('', true) ]" required label="门店状态" v-model="info.status" :option="option.status"/>
            
      <div style="margin: 1rem 16px 16px;">
        <van-button block type="info" :loading="btnLoading">提交</van-button>
      </div>
    </van-form>
    <!-- <van-form class="page-content" :disabled="btnLoading" @submit="submit">
      <van-field :rules="[ $check('', true) ]" required label="门店名称" :value="info.shopName"/>

      <van-field readonly clickable label="经纬度" :value="info.longitude ? `${ info.longitude },${ info.latitude }` : ''" required placeholder="请选择经纬度" @click="getPosiInfo"/>
      <van-field v-model="info.region" required label="所在区域" placeholder="请输入所在区域"/>
      <van-field v-model="info.shopSite" required label="详细地址" placeholder="请输入详细地址"/>

      <van-field readonly clickable label="计费时间/小时" :value="info.chargeTime" required placeholder="请选择计费时间" @click="showPickerClick('chargeTime')"/>
      <van-field :rules="[ $check('请输入数字', 'number') ]" required v-model.number="info.chargeMoney" label="计费金额/元" placeholder="请输入"/>
      <van-field :rules="[ $check('请输入数字', 'number') ]" required v-model.number="info.freeTime" label="免费时长/分钟" placeholder="请输入"/>
      <van-field readonly clickable label="每日最高消费" :value="info.highest" required placeholder="请选择每日最高消费" @click="showPickerClick('highest')"/>
      <van-field :rules="[ $check('', true) ]" required v-model="info.shopTele" label="门店电话" placeholder="请输入"/>
      <van-field :rules="[ $check('', true) ]" required v-model="info.shopHours" label="营业时间" placeholder="请输入"/>
      <van-field readonly clickable label="门店类型" required :value="info.shopSortId" placeholder="请选择门店类型" @click="showPickerClick('shopSortId')"/>
      <van-field readonly clickable label="门店管理人" :value="info.userName" required placeholder="选择门店管理人" @click="showUserPicker = true"/>
      <van-field readonly clickable clearable label="服务商" :value="info.qdsName" placeholder="选择服务商" @click="showQudaoPicker = true">
        <template #button>
          <van-button v-if="info.qdsName" size="small" type="primary" @click.stop="() => {
            info.qdsName = '';
            info.qdsId = '';
          }">清除</van-button>
        </template>
      </van-field>
      <van-field readonly clickable label="业务员" :value="info.salesmanName" placeholder="选择业务员" @click="showSaleManPicker = true" v-if="roleType < 2"/>
      <van-field readonly clickable label="地图显示" :value="info.ifUsable" required placeholder="请选择状态" @click="showPickerClick('ifUsable')"/>
      <van-field readonly clickable label="门店状态" :value="info.status" required placeholder="请选择状态" @click="showPickerClick('status')"/>
      
      <div style="margin: 1rem 16px 16px;">
        <van-button block type="info" :loading="btnLoading">提交</van-button>
      </div>
    </van-form> -->
    <sele-person ref="person" v-model="person.show" @submit="person.sele"></sele-person>
  </div>
</template>

<script>
export default {
  data() {
    return {
      info: {
        salesmanName: '',
        salesmanId: '',
        userName: '',
        userId: '',
        shopName: '',
        shopSite: '',
        highest: '20',
        shopPhotBase: '',
        shopHours: '',
        shopPhotUrl: '',
        region: '',
        chargeUnit: '小时',
        longitude: '',
        latitude: '',
        shopTele: '',
        chargeTime: '1',
        chargeMoney: '',
        freeTime: '',
        qdsId: '',
        qdsName: '',
        ifUsable: 0,
        status: 0
      },
      btnLoading: false,

      modify: false,
      roleType: this.$store.state.userInfo.roleType,
      shareType: this.$store.state.userInfo.shareType,

      option: {
        ifUsable: [
          { value: 0, label: '显示' },
          { value: 1, label: '隐藏' }
        ],
        status: [
          { value: 0, label: '删除' },
          { value: 1, label: '恢复' }
        ],
        chargeUnit: [
          { value: 0, label: '小时' },
          { value: 1, label: '分钟' }
        ],
        chargeTime: [
          { value: 30, label: '0.5' },
          { value: 1, label: '1' },
          { value: 2, label: '2' },
          { value: 3, label: '3' }
        ],
        highest: [
          { value: 20, label: '20' },
          { value: 30, label: '30' },
          { value: 40, label: '40' },
          { value: 50, label: '50' },
          { value: 60, label: '60' },
          { value: 70, label: '70' },
          { value: 80, label: '80' }
        ],
        shopSortId: []
      },

      person: {
        show: false,
        type: '',
        showBlank: (type, role) => {
          this.person.type = type;
          this.$refs.person.changeRole(role);
          this.person.show = true;
        },
        sele: (user) => {
          let type = this.person.type;
          this.info[type + 'Name'] = user.userName;
          this.info[type + 'Id'] = user.userId;
        }
      }
    };
  },
  methods: {
    selePosi() {
      
    },
    setValue(info) {
      this.modify = true;
      this.info = info;
    },
    goBack() {
      this.$router.go(-1);
    },
    getPosiInfo() {
      let config = this.$store.state.config;
      window.wx.config({ ...config, debug: false, jsApiList: [ 'scanQRCode', 'chooseImage', 'uploadImage', 'getLocation', 'getLocation', 'openLocation' ] });
      window.wx.getLocation({
        type: 'wgs84', 
        success: res => {
          let latitude = res.latitude; 
          let longitude = res.longitude;
          this.geocoder.getAddress(new qq.maps.LatLng(latitude, longitude));
          this.form.longitude = longitude;
          this.form.latitude = latitude;
          window.wx.openLocation({ latitude, longitude, scale: 23, infoUrl: '' });
        }
      });
    },
    getSortId() {
      this.$axios.get('/api/ShopSortController/getShopSortList', { 
        page: 1, size: 1000 
      }).then(res => {      
        let list = res.list || [];
        this.option.shopSortId = list.map(item => { 
          return { value: item.shopSortId, label: item.shopSortName };
        });
      });
    },
    submit() {

    }
  },
  mounted() { 
    this.getSortId();
  }
};
</script>